package Test0109;

import java.util.ArrayList;
import java.util.List;

public class CC {
    private String companyName; // 公司名称
    private List<EE> employees; // 员工列表

    public CC(String companyName) {
        this.companyName = companyName;
        this.employees = new ArrayList<>();
    }

    // 添加员工
    public void add(EE employee) {
        employees.add(employee);
    }

    // 打印所有员工信息
    public void printAll() {
        System.out.println("公司名称: " + companyName);
        for (EE employee : employees) {
            System.out.println(employee);
        }
    }

    // 找出年龄最大员工
    public EE m1() {
        EE maxAgeEmployee = null;
        for (EE employee : employees) {
            if (maxAgeEmployee == null || employee.getAge() > maxAgeEmployee.getAge()) {
                maxAgeEmployee = employee;
            }
        }
        return maxAgeEmployee;
    }

    // 找出工资最低员工
    public EE m2() {
        EE minSalaryEmployee = null;
        for (EE employee : employees) {
            if (minSalaryEmployee == null || employee.getSalary() < minSalaryEmployee.getSalary()) {
                minSalaryEmployee = employee;
            }
        }
        return minSalaryEmployee;
    }

    // 找出指定员工
    public EE m3(String name) {
        for (EE employee : employees) {
            if (employee.getName().equals(name)) {
                return employee;
            }
        }
        return null; // 如果未找到，返回 null
    }

    // 求平均工资
    public double m4() {
        double totalSalary = 0;
        for (EE employee : employees) {
            totalSalary += employee.getSalary();
        }
        return employees.size() > 0 ? totalSalary / employees.size() : 0;
    }

    // 找工资高于平均工资的员工
    public List<EE> m5() {
        List<EE> aboveAverage = new ArrayList<>();
        double averageSalary = m4();
        for (EE employee : employees) {
            if (employee.getSalary() > averageSalary) {
                aboveAverage.add(employee);
            }
        }
        return aboveAverage;
    }
}